/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.bsn.common;

import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import org.hutech09.jsale.entity.ICommonEntity;

/**
 *
 * @author Nam
 */
@Local
public interface IGenericDao {

    /**
     *
     * @param <T>
     * @param entity
     * @return
     * @throws DataExistsException
     * @throws DataConstraintException
     * @throws DataException
     */
    public <T extends ICommonEntity> T create(T entity) throws DataExistsException;

    /**
     *
     * @param <T>
     * @param entity
     * @return
     * @throws DataNotExistedException
     * @throws DataConstraintException
     * @throws DataException
     */
    public <T extends ICommonEntity> T update(T entity) throws DataNotExistedException;

    /**
     *
     * @param <T>
     * @param entity
     * @return
     * @throws DataNotExistedException
     */
    public <T extends ICommonEntity> T delete(T entity) throws DataNotExistedException;

    public <T extends ICommonEntity> T delete(Class<T> baseClass, Object id) throws DataNotExistedException;

    /**
     *
     * @param <T>
     * @param baseClass
     * @param id
     * @return
     * @throws DataException
     */
    public <T extends ICommonEntity> T find(Class<T> baseClass, Object id);

    /**
     *
     * @param baseClass
     * @param id
     * @return
     * @throws DataException
     */
    public boolean isExisted(Class<? extends ICommonEntity> baseClass, Object id);

    /**
     *
     * @param <T>
     * @param queryName
     * @param parameters
     * @return
     * @throws DataException
     */
    public <T extends ICommonEntity> List<T> findByNamedQuery(String queryName, Map parameters);

    /**
     *
     * @param <T>
     * @param queryName
     * @param parameters
     * @return
     * @throws DataException
     */
    public <T extends ICommonEntity> T getOneByNamedQuery(String queryName, Map parameters);

    public <T extends ICommonEntity> List<T> getAll(Class<T> clazz);

    public <T extends ICommonEntity> List<T> findPaging(Class<T> clazz, int firstIndex, int pageSize, String orderField, boolean desc);

    public <T extends ICommonEntity> List<T> findPaging(Class<T> clazz, int firstIndex, int pageSize, String orderField, boolean desc, Map<String, Object> filter);

    public <T extends ICommonEntity> long count(Class<T> clazz);

    public <T extends ICommonEntity> long count(Class<T> clazz, Map<String, Object> filter);
}
